package 反射;
//测试创建class类的对象有几种方式
public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person=new Student();
        System.out.println(person.name);
        //方式一：通过对象获取
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());
        //方式二：通过forname
        Class c2 = Class.forName("反射.Student");
        System.out.println(c2.hashCode());
        //方式三：通过类名.class
        Class<Student> c3 = Student.class;
        System.out.println(c3.hashCode());
        //方式四：基本内置类型的包装类都有一个Type方法
        Class<Integer> type = Integer.TYPE;
        System.out.println(type);
        Class c5 = c1.getSuperclass();
        System.out.println(c5);
    }
}
class Person{
    public  String name;
    public  int   age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class  Student  extends   Person{
    public  Student(){
        this.name="学生";
    }
}
class  Teacher  extends   Person{
    public   Teacher(){
        this.name="老师";
    }
}
